package com.gdwstudy.list_;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * @author 关道伟
 * @version 1.0
 */
public class List01 {
    public static void main(String[] args) {
        ArrayList arrayList = new ArrayList();
        arrayList.add(new Dog("小黄狗", 4));
        arrayList.add(new Dog("小花狗", 2));
        arrayList.add(new Dog("小黑狗", 3));
        //增强for遍历
        for(Object dog:arrayList){
            System.out.println(dog);
        }
        System.out.println("=====迭代器遍历======");
        //迭代器遍历
        Iterator iterator = arrayList.iterator();
        while(iterator.hasNext()){
            Object dog = iterator.next();
            System.out.println(dog);
        }
    }
}

class Dog {
    private String name;
    private int age;

    public Dog(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Dog{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}